using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;

namespace SDILReader
{

    public static class Globals
    {
        public static Dictionary<int, object> Cache = new Dictionary<int, object>();

        public static OpCode[] multiByteOpCodes;

        public static OpCode[] singleByteOpCodes;

        public static Module[] modules = null;

        public static void LoadOpCodes()
        {
            singleByteOpCodes = new OpCode[256];
            multiByteOpCodes = new OpCode[256];
            FieldInfo[] fields = typeof(OpCodes).GetFields();
            foreach (FieldInfo fieldInfo in fields)
            {
                if (fieldInfo.FieldType != typeof(OpCode))
                {
                    continue;
                }
                OpCode opCode = (OpCode)fieldInfo.GetValue(null);
                ushort num = (ushort)opCode.Value;
                if (num < 256)
                {
                    singleByteOpCodes[num] = opCode;
                    continue;
                }
                if ((num & 0xFF00) != 65024)
                {
                    throw new Exception("Invalid OpCode.");
                }
                multiByteOpCodes[num & 0xFF] = opCode;
            }
        }

        public static string ProcessSpecialTypes(string typeName)
        {
            string result = typeName;
            switch (typeName)
            {
                case "System.string":
                case "System.String":
                case "String":
                    result = "string";
                    break;
                case "System.Int32":
                case "Int":
                case "Int32":
                    result = "int";
                    break;
            }
            return result;
        }
    }


}